import { createSSRApp } from 'vue'
import { createSSRRouter } from '@/router'
import { createSSRStore, key } from '@/store'
import { createSSRI18n } from '@/language/i18n'
import App from './App.vue'
import { sync } from 'vuex-router-sync'
import Vant from 'vant';
import 'vant/lib/index.css';

export function createApp() {
	const app = createSSRApp(App)
	const store = createSSRStore()
	const router = createSSRRouter()
	const i18n = createSSRI18n()
	// app.config.globalProperties.$message = ElMessage
  	sync(store, router)
	app.use(store, key)
	app.use(router)
	app.use(i18n)
	app.use(Vant)
	return { app, router, store }
}

export function asyncDataFilter(actived: any, store: any, route: any) {
	return Promise.all(actived.map((Component: any) => {
		if (Component.asyncData) {
			return Component.asyncData({
				store,
				route
			})
		}
	}))
}